package com.ruoyi.web.controller.lwpq;

import java.util.List;

import com.ruoyi.lwpq.domain.LwpqLwpq;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lwpq.domain.LwpqYght;
import com.ruoyi.lwpq.service.ILwpqYghtService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 劳务用工合同Controller
 * 
 * @author ruoyi
 * @date 2022-03-07
 */
@Controller
@RequestMapping("/lwpq/yght")
public class LwpqYghtController extends BaseController
{
    private String prefix = "lwpq/yght";

    @Autowired
    private ILwpqYghtService lwpqYghtService;

    @RequiresPermissions("lwpq:yght:view")
    @GetMapping()
    public String yght()
    {
        return prefix + "/yght";
    }

    /**
     * 查询劳务用工合同列表
     */
    @RequiresPermissions("lwpq:yght:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LwpqYght lwpqYght)
    {
        startPage();
        lwpqYght.setCreateBy(getLoginName());
        List<LwpqYght> list = lwpqYghtService.selectLwpqYghtList(lwpqYght);
        return getDataTable(list);
    }

    /**
     * 导出劳务用工合同列表
     */
    @RequiresPermissions("lwpq:yght:export")
    @Log(title = "劳务用工合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LwpqYght lwpqYght)
    {
        List<LwpqYght> list = lwpqYghtService.selectLwpqYghtList(lwpqYght);
        ExcelUtil<LwpqYght> util = new ExcelUtil<LwpqYght>(LwpqYght.class);
        return util.exportExcel(list, "劳务用工合同数据");
    }

    /**
     * 新增劳务用工合同
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存劳务用工合同
     */
    @RequiresPermissions("lwpq:yght:add")
    @Log(title = "劳务用工合同", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LwpqYght lwpqYght)
    {
        lwpqYght.setCreateBy(getLoginName());
        return toAjax(lwpqYghtService.insertLwpqYght(lwpqYght));
    }

    /**
     * 修改劳务用工合同
     */
    @RequiresPermissions("lwpq:yght:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LwpqYght lwpqYght = lwpqYghtService.selectLwpqYghtById(id);
        mmap.put("lwpqYght", lwpqYght);
        return prefix + "/edit";
    }

    /**
     * 修改保存劳务用工合同
     */
    @RequiresPermissions("lwpq:yght:edit")
    @Log(title = "劳务用工合同", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LwpqYght lwpqYght)
    {
        lwpqYght.setUpdateBy(getLoginName());;
        return toAjax(lwpqYghtService.updateLwpqYght(lwpqYght));
    }

    /**
     * 删除劳务用工合同
     */
    @RequiresPermissions("lwpq:yght:remove")
    @Log(title = "劳务用工合同", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lwpqYghtService.deleteLwpqYghtByIds(ids));
    }


    @RequiresPermissions("lwpq:yght:import")
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<LwpqYght> util = new ExcelUtil<LwpqYght>(LwpqYght.class);
        List<LwpqYght> yght = util.importExcel(file.getInputStream());
        String message = lwpqYghtService.importYght(yght, updateSupport, getLoginName());
        return AjaxResult.success(message);
    }

    @RequiresPermissions("lwpq:yght:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<LwpqYght> util = new ExcelUtil<LwpqYght>(LwpqYght.class);
        return util.importTemplateExcel("用工合同数据");
    }
}
